package com.wedata.weimob;

import cn.hutool.crypto.digest.MD5;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.wedata.HttpUtils;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class 健萌会员初始化 {

    public static void main(String[] args) throws IOException {

        FileReader fileReader = new FileReader("src\\main\\java\\com\\wedata\\weimob\\健萌生产会员.txt");
        BufferedReader br = new BufferedReader(fileReader);
        String line = br.readLine();
        try{
            List<String[]> list = new ArrayList<>(20);
            boolean bool = false;
            for(;line!=null;line = br.readLine()){
                try{

                    String[] ss = line.split("\t");
                    //Long wid = new JSONObject(微盟分销业务. getUserInfo(ss[1],"")).getJSONObject("data").getLong("wid");
                    //System.out.println(ss[0]+","+wid);
                    if(ss[0].equals("201709")){
                        bool = true;
                    }
                    if(bool){
                        list.add(ss);
                    }
                    if(list.size()==20){
                        System.out.println(ss[0]+","+ss[1]+","+ss[2]);
                        yyy(list);
                        list.clear();
                        //System.out.println(list.size());
                        //break;
                    }
                }catch (Exception ee){
                    System.out.println(ee);
                }

            }
            if(list.size()>0){
                yyy(list);
                list.clear();
            }
        }catch (Exception ex){
            System.out.println(ex);
        }
        br.close();
        fileReader.close();
    }

    public static void yyy(List<String[]> list) {
        String uri = "https://prewedata.gymcity.com.cn/shopapi/weimob/customer/queryRelation";
        JSONArray array = new JSONArray();
        for(String[] args : list){
            JSONObject body = new JSONObject("{\"type\":1,\"areacode\":86,\"source\":\"gym3\"}");
            body.set("gymUserId",args[0]);
            body.set("phone",args[1]);
            body.set("name",args[2]);
            array.add(body);
        }

        System.out.println(array);

        String sign = MD5.create().digestHex(array+"#10092f520524f58e7d466acf55f0338b");
        JSONObject header = new JSONObject("{\"X-TRACEID\":\"uuid\",\"X-APPKEY\":\"13247086457\",\"X-SIGN\":\""+sign+"\"}");

        Long s = System.currentTimeMillis();
        System.out.println(HttpUtils.sendPost(uri,header,array)+":"+(System.currentTimeMillis()-s));
    }
}
